package cn.xyfmzmy.observer.spring;


import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.stereotype.Controller;

@Controller
public class LogicController {

    @Autowired
    private ApplicationContext applicationContext;

    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;


    // applicationEventPublisher不是直接将事件发送给监听器，而是先将事件发给applicationEventMulticaster
    // spring默认是监听器串行消费事件，加这一层是为了支持扩展
    @Autowired
    private ApplicationEventMulticaster applicationEventMulticaster;

    @PostConstruct
    public void test(){
        // true , 说明容器本身就是事件总线
        System.out.println(applicationContext == applicationEventPublisher);
    }
}
